<template>
    <el-card class="box-card" shadow="hover" :style="generateCardStyle" :body-style="{ padding: '0px' }">
      <div :style="generateImageStyle" >
        <el-image :src="generateImagePath(goods.image)" style="width: 100%; height: auto;"
                  @click="handleOpenItem(goods)" >
        </el-image>
      </div>
      <div class="desc-container">
        <div class="price-container">
          <span>￥{{ goods.price/100 }}</span>
          <el-button v-if="index >= 0" icon="el-icon-close" size="mini" plain circle @click="handleDelGoods(index)"></el-button>
        </div>
        <div class="brand-container">
          <span>{{ goods.brandName }} <i class="el-icon-s-check"></i></span>
          <span>{{ goods.deptName }}</span>
        </div>
        <div class="name-container">
          <el-tooltip placement="top">
            <div slot="content" style="width: 250px;" >
              {{ goods.goodsName }}
            </div>
            <span @click="handleOpenItem(goods)" v-html="goods.viewname || goods.goodsName"></span>
          </el-tooltip>
        </div>
      </div>
    </el-card>
</template>

<script>
export default {
  props: {
    goods: {
      type: Object,
      default: {},
    },
    index: {
      type: Number,
      default: -1,
    }
  },
  data() {
    return {
      imgServe: process.env.VUE_APP_BASE_API,
    }
  },
  methods: {
    generateImagePath(path) {
      if (path && path.indexOf('http') !== 0) {
        return this.imgServe + path
      } else {
        return path;
      }
    },
    handleOpenItem(goods) {
      this.$emit('openItem', goods)
    },
    handleDelGoods(index) {
      if (index >= 0) {
        this.$emit('delGoods', index)
      }
    },
    generateCardStyle() {
      if (this.index >= 0) {
        return 'width: 200px; height: 200px;';
      } else {
        return 'width: 250px; height: 250px;';
      }
    },
    generateImageStyle() {
      if (this.index >= 0) {
        return 'width: 200px; height: 300px;';
      } else {
        return 'width: 250px; height: 350px;';
      }
    },
  },
}
</script>

<style scoped>
.box-card {
  width: 200px;
  height: 300px;
  margin-right: 20px;
}

.desc-container {
  padding: 2px 10px;
  .price-container {
    display: flex;
    justify-content: space-between;
    height: 20px;
    line-height: 20px;
    color: #e4393c;
  }
  .name-container {
    font: 12px/150% tahoma,arial,Microsoft YaHei,Hiragino Sans GB,"\u5b8b\u4f53",sans-serif;

    .skcolor_ljg {
      color: #ff0000;
      padding-right: 5px;
    }
  }
  .brand-container {
    display: flex;
    justify-content: space-between;
    height: 20px;
    line-height: 20px;
    color: #999;
    font-size: 12px;
  }
}

.name-container >>> .el-tooltip {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
  text-overflow: ellipsis;
}
</style>
